var path = require('path');
var utils = require('./utils')
var projectRoot = path.resolve(__dirname, '../') + "/"
const webpack = require('webpack');
var merge = require('webpack-merge')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
var CompressionWebpackPlugin = require('compression-webpack-plugin');




var config = {
    entry: {
        app: ['webpack-hot-middleware/client?reload=true?http://localhost:1337', './src/main.js'],
        comm: [
            'vue',
            'vue-router',
            'vuex',
            'nprogress',
            'axios',
            'babel-polyfill',
            'moment',
            'mathjs'
        ]


    },
    output: {
        path: projectRoot + "dist/",
        publicPath: "/",
        filename: 'js/[name].[hash:7].js'
    },
    externals: {
        'pinyin': 'window.pinyin',

    },
    resolve: {
        extensions: ['.json', '.js', '.vue'],
        alias: {
            "m": path.resolve(__dirname, '../models'),
            'vue$': 'vue/dist/vue',
            'src': path.resolve(__dirname, '../src'),
            'assets': path.resolve(__dirname, '../src/assets'),
            'components': path.resolve(__dirname, '../src/components')
        },
        modules: [

            path.join(__dirname, "../node_modules"),
            "../node_modules"
        ]
    },
    resolveLoader: {
        modules: [

            path.join(__dirname, "../node_modules"),
            "../node_modules"
        ],
        "alias": {
            'scss-loader': 'sass-loader',
        },
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader',
                exclude: /node_modules/
            },
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader!sass-loader'

            },
            {
                test: /\.js$/,
                loader: 'babel-loader',



                exclude: /node_modules/
            },
            {
                test: /\.(svg)(\?.*)?$/,
                loader: 'url-loader',
                query: {
                    limit: 8192,
                    name: utils.assetsPath('img/[name].[hash:7].[ext]')
                }

            },
            {
                test: /\.(png|jpe?g|gif)(\?.*)?$/,
                loader: 'url-loader',
                query: {
                    limit: 8192,
                    name: utils.assetsPath('img/[name].[hash:7].[ext]')
                },
                exclude: /node_modules/
            },

            {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
                loader: 'url-loader',   //这个库以前是url 换成webpack2之后加了loader
                query: {
                    limit: 10000,
                    name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
                }
            }
        ]
    },
    devtool: '#source-map',
    plugins: [

        // new webpack.DefinePlugin({
        //     'process.env': true
        // }),
        // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
        // new BundleAnalyzerPlugin({
        //     analyzerMode: 'static'

        // }),

        new webpack.optimize.OccurrenceOrderPlugin(),

        new webpack.NoEmitOnErrorsPlugin(),
        // new webpack.optimize.UglifyJsPlugin({

        //     compress: {
        //         warnings: false
        //     }
        // }),
        new webpack.optimize.CommonsChunkPlugin(
            {
                name: ["vendor"],
                minChunks: 2,
                chunks: ["app", "comm"]
            }

        ),

        // https://github.com/ampedandwired/html-webpack-plugin
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: 'index.html',
            inject: true
        })
    ]




};






module.exports = config

